package com.cn.crmsystem.controller.systemController;

import com.cn.crmsystem.pojo.Department;
import com.cn.crmsystem.pojo.Login;
import com.cn.crmsystem.pojo.ResultJson;
import com.cn.crmsystem.pojo.User;
import com.cn.crmsystem.service.systemService.DeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.xml.transform.Result;
import java.util.Map;


@RestController
@Api(value = "部门管理", tags = "部门增删改查数据接口API")
public class DepartmentController {

    @Autowired
    private DeptService deptService;

    @RequestMapping(value = "/addDept",method = RequestMethod.POST)
    @ApiOperation(value = "新增部门接口", notes = "管理员新增部门", httpMethod = "POST", response = ResultJson.class)
    public ResultJson addDept(@RequestBody @ApiParam(name = "department", value = "部门类类型数据",required = false) Department department){
        System.out.println("----新增部门----");
        Login login = (Login)SecurityUtils.getSubject().getPrincipal();
        System.out.println("-=-=-=-=-==-=-=="+login);
//        Login login = new Login();
//        login.setUser_id(1);
        System.out.println(login.getUser_id());
        return deptService.addDept(department,login);
    }

    @RequestMapping(value = "/selectDept", method = RequestMethod.POST)
    @ApiOperation(value = "查询部门接口", notes = "管理员查询部门接口", httpMethod = "POST", response = ResultJson.class)
    public ResultJson selectDept(@RequestBody @ApiParam(name = "department", value = "部门类类型数据",required = false) Department department){
        System.out.println("----查询部门----");
        return deptService.selectDept(department);
    }

    @RequestMapping(value = "/deleteDept", method = RequestMethod.POST)
    @ApiOperation(value = "删除部门接口", notes = "管理员传入部门id删除部门",httpMethod = "POST", response = ResultJson.class)
    public ResultJson deleteDept(@RequestParam @ApiParam(name = "departmentId", value = "部门id",required = false) Integer departmentId){
        System.out.println("----删除部门----");
        return deptService.deleteDept(departmentId);
    }

    @ResponseBody
    @RequestMapping(value = "/deleteManyDept",method = RequestMethod.POST)
    @ApiOperation(value ="批量删除部门数据接口",notes = "传入要删除的数据id",httpMethod = "post",response = ResultJson.class)
    @ApiImplicitParam(name = "ids",value = "部门id",paramType = "query",dataType = "int",required = false)
    public ResultJson deleteManyDept(Integer[] ids){
        System.out.println(ids.length);
        return deptService.deleteManyDept(ids);
    }

    @RequestMapping(value = "/updateDept", method = RequestMethod.POST)
    @ApiOperation(value = "修改部门接口", notes = "管理员修改部门信息", httpMethod = "POST", response = ResultJson.class)
    public ResultJson updateDept(@RequestBody @ApiParam(name = "department", value = "部门类类型数据",required = false) Department department){
        System.out.println("----修改部门信息----");
        Login login = (Login)SecurityUtils.getSubject().getPrincipal();
        System.out.println("-=-=-=-=-==-=-=="+login);
//        Login login = new Login();
//        login.setUser_id(1);
        System.out.println(login.getUser_id());
        return deptService.updateDept(department, login);
    }

}
